import { _decorator, Component, Node, sys } from 'cc';
import { MAP, WEAPON } from '../Datas/Constant';
import { Gun } from '../../Game/Gun';
const { ccclass, property } = _decorator;

@ccclass('PrefsManager')
export class PrefsManager {

    private static _instance: PrefsManager = null;
    public static get Instance(): PrefsManager {
        if (!PrefsManager._instance) {
            PrefsManager._instance = new PrefsManager();
        }
        return PrefsManager._instance;
    }

    public userData = {
        "Gold": 2000,
        "CurMap": MAP.MAP1,
        "YW": 0,
        "KF": 0,
        "AllWeapon": [WEAPON.签字笔, WEAPON.刻度尺, WEAPON.游标卡尺, WEAPON.自动手枪, WEAPON.MK18玩具枪, WEAPON.左轮手枪, WEAPON.AK102突击步枪, WEAPON.MK18突击步枪,
        WEAPON.MP43散弹枪, WEAPON.Saiga12K散弹枪, WEAPON.榴弹发射器, WEAPON.光束枪, WEAPON.伽马射线枪, WEAPON.电磁炮, WEAPON.阴极射线管, WEAPON.高爆手雷, WEAPON.破片手雷
        ],
        "HaveWeapon": [WEAPON.签字笔],
        // "HaveWeapon": [WEAPON.AK102突击步枪, WEAPON.MK18玩具枪, WEAPON.MK18突击步枪, WEAPON.MP43散弹枪, WEAPON.Saiga12K散弹枪, WEAPON.伽马射线枪, WEAPON.光束枪,
        // WEAPON.刻度尺, WEAPON.左轮手枪, WEAPON.榴弹发射器, WEAPON.游标卡尺, WEAPON.电磁炮, WEAPON.签字笔, WEAPON.自动手枪, WEAPON.阴极射线管,
        // ],
        "CurWeapon": WEAPON.签字笔,
    }

    private constructor() {
        // sys.localStorage.setItem('userData', JSON.stringify(this.userData));
        const value = sys.localStorage.getItem('TLWLSJ_USERData');
        if (value) {
            //有记录就读取  --- 没记录就存入数据
            this.userData = JSON.parse(value);
        } else {
            console.log(`userData is not exist`);
            sys.localStorage.setItem('TLWLSJ_USERData', JSON.stringify(this.userData));
        }
    }

    public saveData() {
        sys.localStorage.setItem('TLWLSJ_USERData', JSON.stringify(this.userData));
    }
}


